import { LowCodeAst } from '@src/config/interface'
import { resolveComponent, h } from 'vue'
// 遍历ast列表，创建vnode
export const createElement = (ast: LowCodeAst[]): globalThis.VNode[] => {
  return ast.map((node) => {
    let childVNode: any
    if (node.children.length > 0) {
      childVNode = createElement(node.children)
    }
    let nodeElement
    if (node.text) {
      nodeElement = h(resolveComponent(node.element), { ...node.props }, () => node.text)
    } else {
      nodeElement = h(resolveComponent(node.element), { ...node.props }, childVNode)
    }
    return nodeElement
  })
}
